<?
class Archive extends Eloquent {
	public static $timestamps=true;

	public function user(){
		return $this->belongs_to("user");
	}

	public function comment(){
		return $this->has_many("comment");
	}

	public function categorie(){
		return $this->belongs_to("categorie");
	}

	public function reply($id){
		return User::find($id)->first();
	}

	public function tag(){
		return $this->has_one("tag");
	}

	public static function hot($limit=9){
		return static::order_by("view","desc")->take($limit)->get();
	}

	public function like($tag=null){
		if ( !is_null($tag) ){
			$tags = Helper::tags($tag);
			$where=null;
			foreach ($tags as $v) {
				$where .= " or title like '%$v%'";
			}
			$archive = DB::query("SELECT * from archives where 1=0 {$where} limit 8");
			return $archive;
		}
		return null;
	}
}
?>